package com.prb.tpn.filter;


import com.prb.tpn.filter.common.TpnRobot;
import com.prb.tpn.filter.dto.StatisticalInfo;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

import java.util.Map;

@Activate(group = {CommonConstants.CONSUMER })
public class TpnFilter implements Filter {

    private TpnRobot tpnRobot;

    public TpnFilter() {

        tpnRobot = new TpnRobot();
    }

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        // 保存IP地址信息1
        StatisticalInfo statisticalInfo = new StatisticalInfo();
        statisticalInfo.setServerName(invoker.getInterface().getName());
        statisticalInfo.setInvokeTime(System.currentTimeMillis());
        tpnRobot.addStatisticalInfo(invoker.getInterface().getName() , statisticalInfo);

        return invoker.invoke(invocation);
    }

}
